#!/bin/bash
source createtableid.env
#找到当前最大的mysql rid
maxtableid=-1
#找到最大的redis ridset中最大的rid
cursor=0
istrue=1
isexist=`redis-cli -h ${REDIS_IP} -p ${REDIS_PORT} -n ${REDIS_DB} exists "createtableidset"`
if [ ${isexist} -ne 0 ]; then
	while [ ${istrue} -ne 0 ]
	do
		ridsetinfo=`redis-cli -h ${REDIS_IP} -p ${REDIS_PORT} -n ${REDIS_DB} sscan "createtableidset" ${cursor}`
		let j=0
		for value in $ridsetinfo; do
			if [ ${j} -eq 0 ]; then
				cursor=${value}
				j=$((${j}+1))
			elif [ ${maxtableid} -lt ${value} ]; then
                maxtableid=${value}
			fi
		done
	done	
fi


if [ ${maxtableid} -eq 0 ]; then
	maxtableid=100000
fi

echo "maxtableid: ${maxtableid}"

let k=0
let tableid=0
while [ ${tableid} -le ${REDIS_MAXTABLEID} ]
do
	tableid=$((${maxtableid}+1))
	k=$((${k}+1))
	redis-cli -h ${REDIS_IP} -p ${REDIS_PORT} -n ${REDIS_DB} sadd "createtableidset" ${tableid}
	if [ ${k} -eq 400 ]; then
		k=0
		sleep 0.1		
	fi
done
